package cn.tedu.review;

import java.io.*;

/**
 * @author ：Dsi
 * @date ：2021/11/17 9:04
 * Describe ：该类用于复习常用流对象的创建方式
 */
public class CreatStream {
    public static void main(String[] args) {
        f1();
        f2();
    }

    private static void f2() {
        Reader r=null;
        try {
            r = new FileReader("D:\\ready\\1.txt");
            //FileReader r1=new FileReader("D:\\ready\\1.txt");
            //BufferedReader r2=new BufferedReader(r1);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void f1() {
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;
        try {
            bis = new BufferedInputStream(new FileInputStream("D:\\ready\\1.txt"));
            //bis2 = new BufferedInputStream(new FileInputStream(new File("D:\\ready\\1.txt")));//纯纯写法
            //InputStream in = new FileInputStream("D:\\ready\\1.txt");//多态写法
            //FileInputStream fis = new FileInputStream("D:\\ready\\1.txt");//纯纯写法
            bos=new BufferedOutputStream(new FileOutputStream("D:\\ready\\2.txt"));
            byte[] bytes=new byte[1024];
            while (bis.read(bytes)!=-1){
                bos.write(bytes,0,bytes.length);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try{
                bis.close();
            }catch (Exception e){
                e.printStackTrace();
            }
            try{
                bos.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
